import os
from datetime import timedelta

from celery import Celery
from celery.schedules import crontab

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'host_manager.settings')

app = Celery('host_manager')

app.config_from_object('django.conf:settings', namespace='CELERY')

app.autodiscover_tasks()

app.conf.beat_schedule = {
    # 密码批量更新
    "batch-update-host-passwords": {
        "task": "app.tasks.batch_update_host_passwords",
        "schedule": timedelta(hours=8),
    },
    # 主机统计
    "statistic-hosts-daily": {
        "task": "app.tasks.statistic_hosts",
        "schedule": crontab(hour=0, minute=0),
    },
}
